<script type="text/javascript" src="<?php echo $this->baseUrl('stuff/jquery/jquery.cookie.js')?>"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl('stuff/jquery/jquery.hotkeys.js')?>"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl('stuff/jstree/jquery.jstree.js')?>"></script>
    
<?php $this->placeholder('toolBar')->captureStart() ?>

<input class="button controlButton" type="button" id="add_default" value="Добавить ниже" />
<input class="button controlButton" type="button" id="add_folder" value="Добавить рядом" />  
<input class="button controlButton" type="button" id="rename" value="Переименовать" /> 
<input class="button controlButton" type="button" id="remove" value="Удалить" /> 
<input class="button controlButton" type="button" id="cut" value="Вырезать" /> 
<input class="button controlButton" type="button" id="paste" value="Вставить" />


<div style="float: right;">

<form action="<?php echo $this->baseUrl('structure/assign')?>" 	method="post">
 <input type="hidden" name="pmid" id="pmid" value="0"/>
    <select name="" id="link-type" class="menu-select">
    	<option value="0">Выберите значение</option>
    	<option value="article">Статья</option>
    	<option value="static">Страница</option>
    	<option value="gallery">Фотогаллерея</option>
    	<option value="price">Прайс</option>
    	<option value="link">Ссылка</option>
    </select>
    
    <div id="selectcontainer" style="display: inline;">
        <select name="linkContainer" class="menu-select" id="linkContainer">
        	<option value=""></option>
        </select> 
    </div>
    <input type="submit" name="assign" value="Связать" />
</form>

</div>
<?php $this->placeholder('toolBar')->captureEnd() ?>
 
 
    <div id="container"> 


<div id="demo" class="demo" style="width: 500px;"></div>	


<script type="text/javascript"> 

/*function createSelect(name, items){

var Result = "<select name='" + name + "'>";
     Result+= "<option value='0'>Выберите</option>";

$.each(items, function(index, item) {
	Result+= "<option value='" + item.guid + "'>" + item.title + "</option>";
	});

	"</select><br />";
	return Result;
}

function createLinksSelect(name, items){

	var Result = "<select class='linksSelect' name='" + name + "'>";

	     Result+= "<option value='0'>Выберите</option>";

	$.each(items, function(index, item) {
		Result+= "<option value='" + item.link + "'>" + item.title + "</option>";
		});

		"</select><br />";
		return Result;
	}
*/

function processChoice(obj)
{
//	$.post('structure/get-menu-tool',{guid:$(obj).val()},function (data){
//		
//
//if (data.type="links")
//{
//	$("#linksTool").append(createLinksSelect('guid',data.items));
//}
//else
//{
//		$("#linksTool").append(createSelect('guid',data.items));
//
//			var params = {
//					changedEl: ".cuselSelect",
//					scrollArrows: false
//				}
//				cuSel(params);
//			$(".cuselSelect").unbind('change');
//			$(".cuselSelect").change(function(){processChoice(this);});
//}			
//			
//		},'json');

}


</script> 
<script type="text/javascript"> 
$(function () { 
    $(".controlButton").click(function () {
        switch(this.id) {
            case "add_default":
                $("#demo").jstree("create", null, "first", { "attr" : { "rel" : this.id.toString().replace("add_", "") } });
                break;                
            case "add_folder":
                $("#demo").jstree("create", null, "before", { "attr" : { "rel" : this.id.toString().replace("add_", "") } });
                break;
            case "search":
                $("#demo").jstree("search", document.getElementById("text").value);
                break;
            case "text": break;
            default:
                $("#demo").jstree(this.id);
                break;
        }
    });
});
</script> 
</div> 




<script>
$(document).ready(function () {
    $('#link-type').change(function () {
        var linkType = $(this).val();
        if (linkType == '0') {
            $('#linkContainer').html('');
            $('#linkContainer').attr('disabled', true);
            return(false);
        }
        
        $('#linkContainer').attr('disabled', true);
        $('#linkContainer').html('<option>загрузка...</option>');
        
        var url = '<?php echo $this->baseUrl ( 'structure/get-sub-select' )?>';
        
        $.get(
            url,
            {'linkType' : linkType},
            function (result) {
                
                if (result.fieldType == 'text') {
                    $('#selectcontainer').html('<input type="text" class="menu-input" name="linkContainer" />');
                    return(true);
                }
                else {
                    var options = '<select id="linkContainer" name="linkContainer" class="menu-select">';
                    
                    $(result.data).each(function() {
                        options += '<option value="' + $(this).attr('linkDescriptor') + '">' + $(this).attr('title') + '</option>';
                    });
                    
                    options += '</select>';

                    
                    $('#selectcontainer').html(options);
                    $('#linkContainer').attr('disabled', false);
                }
            },
            "json"
        );
    });

    
});




</script>